package com.code.soulqlexpress.func;

import com.ql.util.express.ArraySwap;
import com.ql.util.express.InstructionSetContext;
import com.ql.util.express.OperateData;
import com.ql.util.express.instruction.op.OperatorBase;

/**
 * @author yzh
 * @date 2020/1/17
 * @Content: 为null的数据取其默认值
 */
public class NulOperator extends OperatorBase {

    @Override
    public OperateData executeInner(InstructionSetContext instructionSetContext, ArraySwap arraySwap) throws Exception {
        OperateData operateData = arraySwap.get(0);
        Object object = operateData.getObject(instructionSetContext);
        if (object == null) {
            int length = arraySwap.length;
            if (length == 2) {
                return arraySwap.get(1);
            } else {
                return new OperateData(0, Integer.class);
            }
        }
        return arraySwap.get(0);
    }
}
